package com.example.houduan.Service.Impl;

import com.example.houduan.Mapper.CityMapper;
import com.example.houduan.Pojo.City;
import com.example.houduan.Service.CityService;
import com.example.houduan.Utils.PageModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CityServiceImpl implements CityService {

    @Autowired
    CityMapper cityMapper;

    @Override
    public PageModel getCityPage(int num, int size) {
        int count = cityMapper.selectCityCount();
        PageModel pm = new PageModel(num, count, size);
        pm.setList(cityMapper.selectCityLimit((num - 1) * size, size));
        return pm;
    }

    @Override
    public List<City> getCityByConditions(Integer city_id, String city_name) {
        return cityMapper.selectCityByConditions(city_id, city_name);
    }

    @Override
    public int addCity(City city) {
        return cityMapper.insertCity(city);
    }

    @Override
    public int deleteCity(int city_id) {
        return cityMapper.deleteCity(city_id);
    }

    @Override
    public int updateCity(City city) {
        return cityMapper.updateCity(city);
    }

    @Override
    public List<City> getCityList() {
        return cityMapper.selectCityList();
    }
}
